package com.qf.controller;

import com.qf.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

@Controller
@RequestMapping("/user2")
//要将哪些键的数据存入session域中,此时request和session域中各存一份（很少使用，了解即可）
//@SessionAttributes("msg1")
public class UserController2 {

    @RequestMapping("/resp1")
    public String respData(Model model){

        //向model上设置数据
        model.addAttribute("msg","hello springmvc~~");

        return "res1"; //默认转发（上述设置数据的操作默认存入request域）
    }

    @RequestMapping("/resp2")
    public ModelAndView respData2(ModelAndView mav){
        mav.addObject("msg","hello mvc2222~~");

        mav.setViewName("res1");

        return mav;
    }

    @RequestMapping("/resp3")
    public ModelAndView respData3(ModelAndView mav){
        mav.addObject("msg","hello mvc2222~~");

        User user = new User();
        user.setName("zs");
        user.setPwd("1234456");
        user.setBirthday(new Date());

        mav.addObject("user",user);

        mav.setViewName("res2");

        return mav;
    }
}
